Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@empathyco/x-types

Package Overview
Dependencies
Maintainers
5
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@empathyco/x-types

Empathy search types

  • 9.1.0-alpha.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
580
decreased by-17.96%
Maintainers
5
Weekly downloads
 
Created
Source

x-types

TypeScript model types, guards, and jest schemas to use across the X project.

How to install

npm install @empathyco/x-types --save

How to use

The package export several model types that can be used to safely create objects that match the expectations of X packages.

import { RelatedTag } from "@empathyco/x-types";

const relatedTag: RelatedTag = {
  query: "lego",
  tag: "city",
  selected: false,
  previous: "lego",
};

Additionally it also exposes some type guards to check between different types.

import { Filter, isHierarchicalFilter } from "@empathyco/x-types";

const filter: Filter = {
  modelName: "HierarchicalFilter",
  id: "color:red",
  facetId: "color",
  label: "red",
  selected: false,
  children: [],
};
// You can't access filter.children before the `if` because you have a `Filter`, not a `HierarchicalFilter`.

if (isHierarchicalFilter(filter)) {
  // But after using the `isHierarchicalFilter` guard, you can acces it.
  console.log("Children:", filter.children);
}

Finally, there are some jest schemas helpers that you could use to validate your objects.

import { HierarchicalFilterSchema } from "@empathyco/x-types/schemas";
import { Filter, isHierarchicalFilter } from "@empathyco/x-types";

it("is a hierarchical filter", () => {
  const filter: Filter = {
    modelName: "HierarchicalFilter",
    id: "color:red",
    facetId: "color",
    label: "red",
    selected: false,
    children: [],
  };

  expect(filter).toEqual(HierarchicalFilterSchema);
});

How to update the version

You can check if a new version has been published running npm outdated:

npm outdated @empathyco/x-types

And update it using npm update:

npm update --save @empathyco/x-types

Keywords

FAQs

Package last updated on 20 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc